﻿@model Wiwi.ViewModels.ProfileView 
@{
    Layout = "../Shared/_Layout2.cshtml";
    ViewBag.Title = "Home Page";
    var HomeDir = System.Configuration.ConfigurationManager.AppSettings["HomeDirectory"].ToString(); 
}
<script src="@Url.Content("~/Scripts/DateFormat.js")" type="text/javascript" ></script>
<script src="@Url.Content("~/Scripts/WantControl.js")" type="text/javascript" ></script>
<script type="text/jscript" >
    $(document).ready(function () {
        //  UpdateData();
    });
    function formatJSONDate(jsonDate) { var newDate = dateFormat(jsonDate, "mm/dd/yyyy"); return newDate; }
    function UpdateData() {

        $.ajax({
            url: "/Home/IndexWants",
            dataType: 'json',
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            processData: true,
            success: function (data) {
                var str = "";
                str += "<h4 class='tabbed'>Top wants</h4>";
                for (i = 0; i < data.length; i++) {
                    str += "<div class='wiwi-pitches-box'>";
                    str += "<div class='left-col'><img src='/Home/ShowUserImage?Uid=" + data[i].UserID.toString() + "' width='48' height='48' alt='userName' /></div>";
                    str += "<div class='right-col bigger-icon'>";
                    str += "<div class='user-choice'><a href='#delete' class='delete'>X</a><a href='#reply' class='reply'>?</a></div>";
                    str += "<h5>" + data[i].Fname.toString() + ' ' + data[i].Fname.toString() + "</h5>";
                    str += "<p>" + data[i].WantDesc.toString() + "<br />Will swap for non turbo in good condition.</p>";
                    str += "<div class='also-want'>";
                    str += "<p class='move-left'>Also <br />wanted by</p><p class='move-right'></p>";
                    if (data[i].WantbyUsr != "") {
                        var usrs = data[i].WantbyUsr.split('?');
                        for (j = 0; j < usrs.length; j++) {
                            if (usrs[j] != "") {
                                str += "<a href='Home/UserPublicProfile?Uid=" + usrs[j] + "' ><img height ='28px' width='28' src='/Home/ShowUserImage?Uid=" + usrs[j] + "' /></a>";
                            }
                        }
                    }
                    str += "</div>";
                    str += "<p class='tagged'><a href='@HomeDir/Want/Pitch?Wid=" + data[i].WantID.toString() + "&Uid=" + data[i].UserID.toString() + "'>Pitch</a> <a href='/Want/Meto/'>Me2</a></p>";
                    str += "<div class='also-want'><p class='move-left'>Also <br />Wanted by</p><p class='move-right'>and 32 others</p>";
                    //str += "<img src='/Home/ShowUserImage?Uid=" + data[i].UseID.toString() + "' width='32' height='32' alt='userName' />";
                    //str += "<img src='i/gravitar-06.png' width='32' height='32' alt='userName' />";
                    str += "</div></div></div><hr/>";
                    //alert(data[i].UseID.toString())
                }
                document.getElementById("wiwi-top-wants").innerHTML = str;
                // setTimeout("UpdateData()", 8000);

            }
        });
    }
</script>


<div class="grid_8 box-shadow margin-top" id="wiwi-top-wants">
     <h4 class="tabbed">Top wants</h4>
     
      @foreach (var wnt in Model.Want)
      {      
          @Html.Partial("~/Views/Shared/_WantControl.cshtml", wnt)
        
	<hr />   
      }
      <p>
    @Html.ActionLink("More Recent", "MoreRecent", "Home", new { pageid = 1 }, new { @class = "grey-button button-m center" })
    </p>
</div>

